﻿<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/qa-category.tld" prefix="cat"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<script type="text/javascript" src="<%=request.getContextPath()%>/qa/js/catselect.js"></script>
<span class="title1">我要发帖</span>
<table class="mars">
    <html:form action="/question" method="post" enctype="multipart/form-data" onsubmit="return validate(this);">
    <html:hidden property="action" value="add"/>
    <html:hidden property="catId"/>
    <tbody>
    <tr class="even">
        <td align="right">标题</td>
        <td>
            <c:if test="${user_session.type == '1'}">
            <html:text property="title" size="60" maxlength="60"/>*(最长60个字符)
            </c:if>
            <c:if test="${user_session.type != '1'}">
            <html:text property="title" size="60" maxlength="40"/>*(最长40个字符)
            </c:if>
            <c:if test="${user_session.type == '1'}">
            &nbsp;&nbsp;<html:checkbox property="isRequireLogin"/>要求登录才能查看<br>
            	颜色：<html:radio property="titleColor" value="0">无</html:radio>
            	<html:radio property="titleColor" value="1">红</html:radio>
            	<html:radio property="titleColor" value="2">蓝</html:radio>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            	<html:checkbox property="titleIsBold">粗体</html:checkbox>
            </c:if>
        </td>
    </tr> 
    <tr>
        <td align="right">内容</td>
        <td valign="top">
            <table width="100%" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td><html:textarea property="content" cols="70" rows="15"/>*</td>
                    <td style="vertical-align: top"><jsp:include page="help-insertpicture.jsp"/></td>
                </tr>
            </table>
        </td>
    </tr>
    <tr class="even">
        <td align="right">参考</td>
        <td>
            <html:text property="reference" value="http://" size="50" maxlength="100"/>
        </td>
    </tr>
   <tr>
        <td align="right">附件</td>
        <td>
            <html:file property="file" size="50"/>(小于5M,建议英文文件名)
        </td>
    </tr>
    <tr class="even">
        <td align="right">图片</td>
        <td><iframe name="ad" frameborder="0" width="100%" height="25" scrolling="no" src="/question.mrqa?action=uploadImage&imageIn=question&imageArea=questionf[1].content"></iframe>
        </td>
    </tr>
    <tr>
        <td align="right">分类</td>
        <td valign="top">
        		<html:select property="categoryType" multiple="true" size="15" onchange="initSelect1(this.form)">
        			<html:option value="0">MFer 职场&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html:option>
        			<html:option value="1">MFer 招聘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html:option>
        			<html:option value="2">MFer 技术&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html:option>
            </html:select>
            <html:select property="cat1Id" multiple="true" size="15" onchange="selectedCat1Changed(this)">
            	<html:option value="">选择分类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html:option>
            </html:select>
            <html:select property="cat2Id" multiple="true" size="15" onchange="selectedCat2Changed(this)">
                <html:option value="">选择分类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html:option>
            </html:select>
            <html:select property="cat3Id" multiple="true" size="15">
                <html:option value="">选择分类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html:option>
            </html:select>*
            <html:select property="cities" multiple="true" size="15" style="display:none">
                <html:option value="">工作地点&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html:option>
                <html:options collection="cities" property="id" labelProperty="name"/>
            </html:select>
        </td>
    </tr>
    <tr id="emailRow" style="display:none">
    	<td align="right">邮箱</td>
    	<td valign="top">
    		<html:text property="email" value="" size="50" maxlength="100"/>(此邮箱仅用于接收用户在线投递的简历)
    	</td>
    </tr>
    <tr class="even">
        <td align="right"></td>
        <td>
            验证码<html:text property="vc" size="8" maxlength="4" value=""/>*(输入右边图片上的数字)<img src="<%=request.getContextPath()%>/vcimg" width="40" height="20" border="0" align="absbottom"/>&nbsp;&nbsp;&nbsp;
            <c:if test="${disableSubmit == 'true'}">
                <input type="submit" value="提交帖子" disabled />(*项必须填写)
            </c:if>
            <c:if test="${disableSubmit != 'true'}">
                <input type="submit" value="提交帖子" name="submitButt"/>(*项必须填写)
            </c:if>
        </td>
    </tr>
    </tbody>
    </html:form>
</table>
<xml id="catsData">
      <cats id="cats">  
        <cat:insert type="D"/>
      </cats>
</xml>
<script type="text/javascript">
    var prohibitedWords = "<%=com.mr.qa.GlobalConfigs.PROHIBITED_WORDS%>";
    initSelect1(document.questionf[1]);
    function validate(pForm)
    {
        var selectedCatIdValue = getSelectedCatIdValue(pForm);
        if(selectedCatIdValue == "")
        {
            alert("[分类]必须选择");
            return false;
        }
        pForm.catId.value = selectedCatIdValue;
        if(pForm.title.value == "")
        {
            alert("[标题]必须填写");
            pForm.title.focus();
            return false;
        }
        else
        {
            if(pForm.title.value.length < 2)
            {
                alert("[标题]必须大于2个字符");
                pForm.title.focus();
                return false;
            }
        }
        var temporalCheck = tempCheck(pForm.title.value);
        if(!temporalCheck)
        {
            alert("[标题]含有非法字符");
            pForm.title.focus();return false;
        }
        if(pForm.cities.style.display != "none")
        {
        	var citySelected = false;
        	var option = pForm.cities;
        	for(var i = 0; i < option.length; i++)
        	{
        			if (option.options[i].selected && i == 0)break;
          	  if (option.options[i].selected) {
          	  	citySelected = true;
          	  	break;
          	  }
        	}
        	if (!citySelected) {
        		alert("请选择城市");
        		return false;
        	}
        }
        if(pForm.vc.value == "" || pForm.vc.value.length < 4)
        {
            alert("[验证码]必须填写正确");
            pForm.vc.focus();
            return false;
        }
        pForm.submitButt.disabled = true;
        
        var uploadImage = frames["ad"].window.document.getElementById("uploadButton");
        if(uploadImage){
    			uploadImage.disabled = true;
    		}
        return true;
    }
    
    /*
    * temporal validation to prevent prohibited key words
    */
    function tempCheck(title)
    {
        var prohibitedWordArr = prohibitedWords.split(",");
        var prohibitedWord;
        for(var i=0;i<prohibitedWordArr.length;i++)
        {
            prohibitedWord = prohibitedWordArr[i];
            if(prohibitedWord.length > 0 && title.indexOf(prohibitedWord) >= 0)
            {
                return false;
            }
        }
        return true;
    }
    
    function addPictureLink()
    {
        var ret = prompt("请输入图片的http地址，如http://www.mainframer.cn/images/aa.gif","http://");
        if(ret   ==   null)   
        {
            return;
        }   
        else if(ret.replace(/^\s+|\s+$/g,"") == "")   
        {
            return;
        }
        else 
        {
            //how to insert into textarea
        }
    }
</script>
